import React from 'react';
import { Tabs, List, Icon } from 'antd';
import { formatMessage, connect } from 'umi';
import { get as getPath } from 'object-path';
import LinkTo from '@/components/LinkTo';
import authHelper from '@/utils/auth/helper';
import AuthCode from '@/utils/auth/AuthCode';
import style from '../Gateway.less';

const { checkCode } = authHelper;

class noticeList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            goMore: 1
        };
        this.authCode = new AuthCode(props.route.code).authCode;
    }

    // 切换面板
    activeTab = activekey => {
        if (activekey === 'list1') {
            this.setState({
                goMore: 1
            });
        } else if (activekey === 'list3') {
            this.setState({
                goMore: 3
            });
        } else {
            this.setState({
                goMore: 2
            });
        }
    };

    render() {
        const { TabPane } = Tabs;
        const { data } = this.props;
        // const {
        //     gateway: { newsList }
        // } = this.props;
        return (
            <div className={style.bgfff} style={{ height: '260px' }}>
                <Tabs defaultActiveKey="list1" onChange={this.activeTab}>
                    {checkCode(this.authCode('notice')) && (
                        <TabPane
                            tab={`${formatMessage({
                                id: 'list.notice.title'
                            })} (${data.noticeCount})`}
                            key="list1"
                        >
                            <List
                                className={style.wnlist}
                                itemLayout="horizontal"
                                dataSource={data.noticeList}
                                renderItem={item => (
                                    <List.Item key={item.id.toString()}>
                                        <List.Item.Meta
                                            className={style.workListMeta}
                                            title={
                                                <LinkTo
                                                    to="/personal/portal/notice/noticeDetail"
                                                    query={{
                                                        noticeId: item.id
                                                    }}
                                                >
                                                    {item.title}
                                                </LinkTo>
                                                // <a
                                                //     onClick={() => (
                                                //         // history.push(
                                                //         //     `/personal/portal/notice/noticeDetail?noticeId=${item.id}`
                                                //         // )
                                                //         <LinkTo
                                                //             to={`/personal/portal/notice/noticeDetail?noticeId=${item.id}`}
                                                //         />
                                                //     )}
                                                // >
                                                //     {item.title}
                                                // </a>
                                            }
                                        />
                                        <div className={style.wnlist_time}>
                                            {item.startTime}
                                        </div>
                                    </List.Item>
                                )}
                            />
                        </TabPane>
                    )}
                    {/* <TabPane
                        tab={formatMessage({
                            id: 'list.news.title'
                        })}
                        key="list2"
                    >
                        <List
                            className={style.wnlist}
                            itemLayout="horizontal"
                            dataSource={newsList.filter(
                                (item, index) => index < 3
                            )}
                            renderItem={item => (
                                <List.Item key={item.updateUser.toString()}>
                                    <List.Item.Meta
                                        title={
                                            <a
                                                href="#"
                                                style={{
                                                    width: '100%',
                                                    overflow: 'hidden',
                                                    textOverflow:
                                                        '-o-ellipsis-lastline',
                                                    display: '-webkit-box',
                                                    WebkitLineClamp: '1',
                                                    flexDirection: 'column',
                                                    WebkitBoxOrient: 'vertical'
                                                }}
                                            >
                                                {item.title}
                                            </a>
                                        }
                                    />
                                    <div className={style.wnlist_time}>
                                        {item.time}
                                    </div>
                                </List.Item>
                            )}
                        />
                    </TabPane> */}

                    {checkCode(this.authCode('rules')) && (
                        <TabPane
                            tab={`${formatMessage({
                                id: 'list.rules.title'
                            })} (${data.ruleCount})`}
                            key="list3"
                        >
                            <List
                                className={style.wnlist}
                                itemLayout="horizontal"
                                dataSource={data.ruleList}
                                renderItem={item => (
                                    <List.Item key={item.id.toString()}>
                                        <List.Item.Meta
                                            className={style.workListMeta}
                                            title={
                                                <LinkTo
                                                    to="/personal/portal/rules/rulesDetail"
                                                    query={{
                                                        ruleId: item.id
                                                    }}
                                                >
                                                    {item.title}
                                                </LinkTo>
                                                // <a
                                                //     onClick={() => (
                                                //         history.push(
                                                //             `/personal/portal/rules/rulesDetail?ruleId=${item.id}`
                                                //         )
                                                //     )}
                                                // >
                                                //     {item.title}
                                                // </a>
                                            }
                                        />
                                        <div className={style.wnlist_time}>
                                            {item.startTime}
                                        </div>
                                    </List.Item>
                                )}
                            />
                        </TabPane>
                    )}
                </Tabs>
                {data.noticeCount > 3 && getPath(this.state, 'goMore') === 1 ? (
                    <LinkTo
                        className={style.wnlist_more}
                        to="/personal/portal/notice"
                    >
                        {formatMessage({
                            id: 'list.btn.more'
                        })}{' '}
                        <Icon type="right" />
                    </LinkTo>
                ) : // <a
                //     className={style.wnlist_more}
                //     onClick={() => <LinkTo to="/personal/portal/notice" />}
                // >
                //     {formatMessage({
                //         id: 'list.btn.more'
                //     })}{' '}
                //     <Icon type="right" />
                // </a>
                    null}
                {data.ruleCount > 3 && getPath(this.state, 'goMore') === 3 ? (
                    // <a
                    //     className={style.wnlist_more}
                    //     onClick={() => <LinkTo to="/personal/portal/rules" />}
                    // >
                    <LinkTo
                        className={style.wnlist_more}
                        to="/personal/portal/rules"
                    >
                        {formatMessage({
                            id: 'list.btn.more'
                        })}{' '}
                        <Icon type="right" />
                    </LinkTo>
                ) : // </a>
                    null}
            </div>
        );
    }
}
export default connect(({ gateway }) => ({
    gateway
}))(noticeList);
